﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

namespace _180FrameWork.CustControls
{
    public class CustDataGridViewFuzzyQueryBoxColumn : DataGridViewColumn
    {

        /// <summary>
        /// 选中事件
        /// </summary>
        [Category("Data")]
        [Description("CustDataGridViewFuzzyQueryBoxColumn_ItemSelectedDescr")]
        public event AfterSelectorEventHandler AfterSelector;
        /// <summary>
        /// 查询字符串变更事件
        /// </summary>
        [Category("Data")]
        [Description("CustDataGridViewFuzzyQueryBoxColumn_QueryStringChangedDescr")]
        public event QueryStringChangeEventHandler QueryStringChangeEvent;

        private object m_dataSoruce = null;
        private string sDisplayMember = "";
        private string sDisplayField = "";

        public string SDisplayField
        {
            get { return sDisplayField; }
            set { sDisplayField = value; }
        }

        public string SDisplayMember
        {
            get { return sDisplayMember; }
            set { sDisplayMember = value; }
        }

        public CustDataGridViewFuzzyQueryBoxColumn()
            : base(new CustDataGridViewFuzzyQueryBoxCell())
        {

        }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                if (value != null && !value.GetType().IsAssignableFrom(typeof(CustDataGridViewFuzzyQueryBoxCell)))
                {
                    throw new InvalidCastException("不是CustDataGridViewFuzzyQueryBoxCell");
                }

                base.CellTemplate = value;
            }
        }
        private CustDataGridViewFuzzyQueryBoxCell ComboBoxCellTemplate
        {
            get
            {
                return (CustDataGridViewFuzzyQueryBoxCell)this.CellTemplate;
            }
        }

        //private IList _DataSource;

        //public IList DataSource
        //{
        //    get
        //    {
        //        return this._DataSource;
        //    }
        //    set
        //    {
        //        this._DataSource = value;
        //    }
        //}

        public void OnAfterSelector(object sender, AfterSelectorEventArgs e)
        {
            if (AfterSelector != null)
            {
                AfterSelector(sender, e);
            }
        }

        public void OnQueryStringChange(object sender, QueryStringChangeEventArgs e)
        {
            if (QueryStringChangeEvent != null)
            {
                QueryStringChangeEvent(sender, e);
            }
        }
    }
}
